using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Lottery.Data;

namespace Lottery
{
	enum DialogState {dsAdd, dsUpdate, dsDelete};
	/// <summary>
	/// Summary description for frmAddDrawing.
	/// </summary>
	public class frmAddDrawing : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox tbxNumber;
		private System.Windows.Forms.DateTimePicker tbxDate;
		private System.Windows.Forms.TextBox tbxFirst;
		private System.Windows.Forms.TextBox tbxSecond;
		private System.Windows.Forms.TextBox tbxThird;
		private System.Windows.Forms.TextBox tbxFourth;
		private System.Windows.Forms.TextBox tbxFifth;
		private System.Windows.Forms.TextBox tbxSixth;
		private System.Windows.Forms.Label lblNumber;
		private System.Windows.Forms.Label lblDate;
		private System.Windows.Forms.Label lblFirst;
		private System.Windows.Forms.Label lblSecond;
		private System.Windows.Forms.Label lblThird;
		private System.Windows.Forms.Label lblFourth;
		private System.Windows.Forms.Label lblSixth;
		private System.Windows.Forms.Label lblFifth;
		private System.Windows.Forms.Label lblCombination;
		private System.Windows.Forms.Button btnAdd;
		private System.Windows.Forms.Button btnCancel;
		private DialogState state;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public void ShowAdd()
		{
			state = DialogState.dsAdd;
			this.ShowDialog();
		}

		public void ShowUpdate(Drawing d)
		{
			state = DialogState.dsUpdate;
			btnAdd.Text = "Update";
			tbxNumber.Text = d.Number.ToString();
			tbxNumber.ReadOnly = true;
			tbxDate.Text = d.Date.ToShortDateString();
			tbxFirst.Text = d.combination[0].ToString();
			tbxSecond.Text = d.combination[1].ToString();
			tbxThird.Text = d.combination[2].ToString();
			tbxFourth.Text = d.combination[3].ToString();
			tbxFifth.Text = d.combination[4].ToString();
			tbxSixth.Text = d.combination[5].ToString();
			this.ShowDialog();
		}

		public frmAddDrawing()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.tbxNumber = new System.Windows.Forms.TextBox();
			this.tbxDate = new System.Windows.Forms.DateTimePicker();
			this.btnAdd = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.tbxFirst = new System.Windows.Forms.TextBox();
			this.tbxSecond = new System.Windows.Forms.TextBox();
			this.tbxThird = new System.Windows.Forms.TextBox();
			this.tbxFourth = new System.Windows.Forms.TextBox();
			this.tbxFifth = new System.Windows.Forms.TextBox();
			this.tbxSixth = new System.Windows.Forms.TextBox();
			this.lblNumber = new System.Windows.Forms.Label();
			this.lblDate = new System.Windows.Forms.Label();
			this.lblFirst = new System.Windows.Forms.Label();
			this.lblSecond = new System.Windows.Forms.Label();
			this.lblThird = new System.Windows.Forms.Label();
			this.lblFourth = new System.Windows.Forms.Label();
			this.lblSixth = new System.Windows.Forms.Label();
			this.lblFifth = new System.Windows.Forms.Label();
			this.lblCombination = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// tbxNumber
			// 
			this.tbxNumber.Location = new System.Drawing.Point(8, 24);
			this.tbxNumber.Name = "tbxNumber";
			this.tbxNumber.TabIndex = 0;
			this.tbxNumber.Text = "";
			// 
			// tbxDate
			// 
			this.tbxDate.CustomFormat = "DD/MM/YYYY";
			this.tbxDate.Format = System.Windows.Forms.DateTimePickerFormat.Short;
			this.tbxDate.Location = new System.Drawing.Point(120, 24);
			this.tbxDate.Name = "tbxDate";
			this.tbxDate.Size = new System.Drawing.Size(96, 20);
			this.tbxDate.TabIndex = 1;
			this.tbxDate.Value = new System.DateTime(2005, 6, 22, 0, 0, 0, 0);
			// 
			// btnAdd
			// 
			this.btnAdd.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.btnAdd.Location = new System.Drawing.Point(32, 240);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.TabIndex = 2;
			this.btnAdd.Text = "Add";
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.Location = new System.Drawing.Point(112, 240);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 3;
			this.btnCancel.Text = "Cancel";
			// 
			// tbxFirst
			// 
			this.tbxFirst.Location = new System.Drawing.Point(88, 80);
			this.tbxFirst.Name = "tbxFirst";
			this.tbxFirst.TabIndex = 4;
			this.tbxFirst.Text = "";
			// 
			// tbxSecond
			// 
			this.tbxSecond.Location = new System.Drawing.Point(88, 104);
			this.tbxSecond.Name = "tbxSecond";
			this.tbxSecond.TabIndex = 5;
			this.tbxSecond.Text = "";
			// 
			// tbxThird
			// 
			this.tbxThird.Location = new System.Drawing.Point(88, 128);
			this.tbxThird.Name = "tbxThird";
			this.tbxThird.TabIndex = 6;
			this.tbxThird.Text = "";
			// 
			// tbxFourth
			// 
			this.tbxFourth.Location = new System.Drawing.Point(88, 152);
			this.tbxFourth.Name = "tbxFourth";
			this.tbxFourth.TabIndex = 7;
			this.tbxFourth.Text = "";
			// 
			// tbxFifth
			// 
			this.tbxFifth.Location = new System.Drawing.Point(88, 176);
			this.tbxFifth.Name = "tbxFifth";
			this.tbxFifth.TabIndex = 8;
			this.tbxFifth.Text = "";
			// 
			// tbxSixth
			// 
			this.tbxSixth.Location = new System.Drawing.Point(88, 200);
			this.tbxSixth.Name = "tbxSixth";
			this.tbxSixth.TabIndex = 9;
			this.tbxSixth.Text = "";
			// 
			// lblNumber
			// 
			this.lblNumber.Location = new System.Drawing.Point(8, 8);
			this.lblNumber.Name = "lblNumber";
			this.lblNumber.Size = new System.Drawing.Size(100, 16);
			this.lblNumber.TabIndex = 10;
			this.lblNumber.Text = "Number:";
			// 
			// lblDate
			// 
			this.lblDate.Location = new System.Drawing.Point(120, 8);
			this.lblDate.Name = "lblDate";
			this.lblDate.Size = new System.Drawing.Size(100, 16);
			this.lblDate.TabIndex = 11;
			this.lblDate.Text = "Date:";
			// 
			// lblFirst
			// 
			this.lblFirst.Location = new System.Drawing.Point(32, 80);
			this.lblFirst.Name = "lblFirst";
			this.lblFirst.Size = new System.Drawing.Size(48, 20);
			this.lblFirst.TabIndex = 12;
			this.lblFirst.Text = "First:";
			this.lblFirst.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblSecond
			// 
			this.lblSecond.Location = new System.Drawing.Point(32, 104);
			this.lblSecond.Name = "lblSecond";
			this.lblSecond.Size = new System.Drawing.Size(48, 20);
			this.lblSecond.TabIndex = 13;
			this.lblSecond.Text = "Second:";
			this.lblSecond.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblThird
			// 
			this.lblThird.Location = new System.Drawing.Point(32, 128);
			this.lblThird.Name = "lblThird";
			this.lblThird.Size = new System.Drawing.Size(48, 20);
			this.lblThird.TabIndex = 14;
			this.lblThird.Text = "Third:";
			this.lblThird.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblFourth
			// 
			this.lblFourth.Location = new System.Drawing.Point(32, 152);
			this.lblFourth.Name = "lblFourth";
			this.lblFourth.Size = new System.Drawing.Size(48, 20);
			this.lblFourth.TabIndex = 15;
			this.lblFourth.Text = "Fourth:";
			this.lblFourth.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblSixth
			// 
			this.lblSixth.Location = new System.Drawing.Point(32, 200);
			this.lblSixth.Name = "lblSixth";
			this.lblSixth.Size = new System.Drawing.Size(48, 20);
			this.lblSixth.TabIndex = 16;
			this.lblSixth.Text = "Sixth:";
			this.lblSixth.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblFifth
			// 
			this.lblFifth.Location = new System.Drawing.Point(32, 176);
			this.lblFifth.Name = "lblFifth";
			this.lblFifth.Size = new System.Drawing.Size(48, 20);
			this.lblFifth.TabIndex = 17;
			this.lblFifth.Text = "Fifth:";
			this.lblFifth.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblCombination
			// 
			this.lblCombination.Location = new System.Drawing.Point(8, 56);
			this.lblCombination.Name = "lblCombination";
			this.lblCombination.Size = new System.Drawing.Size(100, 16);
			this.lblCombination.TabIndex = 18;
			this.lblCombination.Text = "Combination:";
			// 
			// frmAddDrawing
			// 
			this.AcceptButton = this.btnAdd;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(224, 269);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.lblCombination,
																		  this.lblFifth,
																		  this.lblSixth,
																		  this.lblFourth,
																		  this.lblThird,
																		  this.lblSecond,
																		  this.lblFirst,
																		  this.lblDate,
																		  this.lblNumber,
																		  this.tbxSixth,
																		  this.tbxFifth,
																		  this.tbxFourth,
																		  this.tbxThird,
																		  this.tbxSecond,
																		  this.tbxFirst,
																		  this.btnCancel,
																		  this.btnAdd,
																		  this.tbxDate,
																		  this.tbxNumber});
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmAddDrawing";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Add Drawing";
			this.ResumeLayout(false);

		}
		#endregion

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			Drawing d = new Drawing(Convert.ToInt32(tbxNumber.Text), Convert.ToDateTime(tbxDate.Text));
			d.combination[0] = Convert.ToInt32(tbxFirst.Text);
			d.combination[1] = Convert.ToInt32(tbxSecond.Text);
			d.combination[2] = Convert.ToInt32(tbxThird.Text);
			d.combination[3] = Convert.ToInt32(tbxFourth.Text);	
			d.combination[4] = Convert.ToInt32(tbxFifth.Text);
			d.combination[5] = Convert.ToInt32(tbxSixth.Text);
			switch(state)
			{
				case DialogState.dsAdd:
					DrawingManager.Insert(d);
				break;
				case DialogState.dsUpdate:
					DrawingManager.Update(d);
				break;
				case DialogState.dsDelete:
					/*DrawingManager.Update(d);*/
				break;
				default:
				break;
			}
		}
	}
}
